package com.hos.controller;

import com.hos.framework.Result;
import com.hos.framework.ResultUtil;
import com.hos.service.HospitalService;
import com.hos.utils.DateUtil;
import com.hos.vo.HospitalStatVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Hanyixuan
 */
@RestController
@RequestMapping("/api/hospital")
public class HospitalController {
    @Autowired
    HospitalService hospitalService;


    @GetMapping("/getHospitalStat")
    public Result<Map<String,Object>> getBorrowStat(){
        Map<String,Object> map = new HashMap<>(16);
        List<String> days = DateUtil.getDaysBetwwen(7);

        map.put("columnName",days);
        HospitalStatVO xinguanVO = new HospitalStatVO();
        HospitalStatVO aiziVO = new HospitalStatVO();

        xinguanVO.setName("新冠肺炎");
        aiziVO.setName("肺结核");
        xinguanVO.setType("bar");
        aiziVO.setType("bar");
        List<Integer> xinguanData = new ArrayList<>();
        List<Integer> aiziData = new ArrayList<>();
        for (String day:days) {
            xinguanData.add(hospitalService.getxinguanCount(day));
            aiziData.add(hospitalService.getaiziCount(day));
        }
        xinguanVO.setData(xinguanData);
        aiziVO.setData(aiziData);

        List<HospitalStatVO> list = new ArrayList<>();
        list.add(xinguanVO);
        list.add(aiziVO);

        map.put("columnValue",list);

        return ResultUtil.ok(map);

    }
}
